package org.alerve.android.resourcebuilder.fieldmodules;

import static org.alerve.android.resourcebuilder.fieldmodules.SpinnerArrayAdapter.Creator.create;

import java.lang.reflect.Field;

import org.alerve.android.resourcebuilder.AbstractDirector.ModuleClass;
import org.alerve.android.resourcebuilder.IFieldModule;

import android.content.Context;
import android.widget.BaseAdapter;
import android.widget.Spinner;

/**
 * 
 * Field Module used to handle annotaions related to {@link Spinner} objects.
 * 
 * @author pablo
 * 
 */
@ModuleClass(Spinner.class)
public class SpinnerFieldModule implements IFieldModule<Spinner> {

	/*
	 * (non-Javadoc)
	 * @see org.alerve.android.resourcebuilder.IFieldModule#build(android.content.Context, java.lang.Object, java.lang.reflect.Field)
	 */
	@Override
	public boolean build(Context context, Spinner subject, Field field) {
		SpinnerArrayAdapter annotation = field
				.getAnnotation(SpinnerArrayAdapter.class);
		if (annotation != null) {
			BaseAdapter adapter = create(context, annotation);
			subject.setAdapter(adapter);
			return true;
		}
		return false;
	}
}
